package com.example.mybaseapp

import com.example.mybaseapp.widget.my_circle_seekbar.CircleUtil
import org.junit.Test

import org.junit.Assert.*
import kotlin.math.acos
import kotlin.math.atan2
import kotlin.math.sqrt

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {

    data class GoodTest(var s1:String, var s2:String)
    @Test
    fun tt1(){
        val list = mutableMapOf<String,GoodTest>()
        list["1"] = GoodTest("1","2")
        list["2"] = GoodTest("1","2")
        list["3"] = GoodTest("1","2")

        val g = list["2"]!!
        g.s2 = "33"
        println("${list["2"]}")
    }

    @Test
    fun tt(){
        val maxZoom = 6.0f
        val zoom1 = 1.0f
        val zoom2 = 0.1f
        val zoom3 = 2.0f
        val calculatedZoom1 = calculateZoom(maxZoom, zoom1)
        val calculatedZoom2 = calculateZoom(maxZoom, zoom2)
        val calculatedZoom3 = calculateZoom(maxZoom, zoom3)
        println("For maxZoom = $maxZoom:")
        println("If zoom is $zoom1, calculatedZoom is $calculatedZoom1")
        println("If zoom is $zoom2, calculatedZoom is $calculatedZoom2")
        println("If zoom is $zoom3, calculatedZoom is $calculatedZoom3")
    }

    fun calculateZoom(maxZoom: Float, zoom: Float): Float {
        val calculatedZoom = (zoom - 0.1f) * ((maxZoom - 1.5f) / 1.9f) + 1.5f
        return calculatedZoom
    }

    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun at(){
        val degree1=-233.35934
        val degree2=127.05882
//        Fireg diff=-0.41815186 errorDegreeRange:5.2941175

        // 计算角度差
        var diff =  degree1 - degree2
        println("diff=$diff")
        if(diff>360){
            diff %= 360
        }else if(diff<-360){
            diff %= -360
        }
        println("diff2=$diff")
//        println(-120 % 360)
//        println(-370 % -360)
    }


//    fun calculateBangle(Ax: Double, Ay: Double, Cx: Double, Cy: Double): Double {
//        val angleInRadians = atan2(Ay - Cy, Ax - Cx)
////        val angleInDegrees = Math.toDegrees(angleInRadians)
//        val angleInDegrees = (angleInRadians * 180.0 / kotlin.math.PI).toDouble()
//        return angleInDegrees
//    }
//
//    @Test
//    fun main() {
//        val A = 0.0
//        val Ay = 4.0
//        val C = 4.0 * sqrt(3.0)
//        val Cy = 0.0
//
//        val bDegree = calculateBangle(A, Ay, C, Cy)
//        println("角 B 的度数: $bDegree")
//    }


    fun calculateBAngle(Ax: Double, Ay: Double, Bx: Double, By: Double, Cx: Double, Cy: Double): Double {
        val ABx = Ax - Bx
        val ABy = Ay - By
        val BCx = Cx - Bx
        val BCy = Cy - By
        val angleInRadians = atan2(ABy * BCx - ABx * BCy, ABx * BCx + ABy * BCy)
//        val angleInDegrees = (angleInRadians * 180.0 / kotlin.math.PI).toDouble()
        val angleInDegrees = Math.toDegrees(angleInRadians)
        return angleInDegrees
    }
//
//    @Test
//    fun main() {
//        val Ax = 0.0
//        val Ay = 4.0
//        val Bx = 0.0
//        val By = 0.0
//        val Cx = 4.0 * kotlin.math.sqrt(3.0)
//        val Cy = 0.0
//
//        val bDegree = calculateBAngle(Ax, Ay, Bx, By, Cx, Cy)
//        println("角 B 的度数: $bDegree")
//    }
//
//
//    fun calculateBAngle(Dx: Double, Dy: Double, Ex: Double, Ey: Double, Fx: Double, Fy: Double): Double {
//        val DEy = Dy - Ey
//        val DEx = Dx - Ex
//        val FEy = Fy - Ey
//        val FEx = Fx - Ex
//        val angleInRadians = atan2(DEy * FEx - DEx * FEy, DEx * FEx + DEy * FEy)
//        val angleInDegrees = (angleInRadians * 180.0 / Math.PI).toDouble()
//        return angleInDegrees
//    }

    @Test
    fun main() {
//        val Dx = -5.0 / sqrt(2.0)
//        val Dy = 5.0 / sqrt(2.0)
//        val Ex = 0.0
//        val Ey = 0.0
//        val Fx = 5.0
//        val Fy = 0.0
//
//        val eDegree = calculateBAngle(Dx, Dy, Ex, Ey, Fx, Fy)
//        println("角 E 的度数: $eDegree")

//        val Tx = 0.0F
//        val Ty = 1.0F
//        val Yx = 0.0F
//        val Yy = 0.0F
//        val Ux = 5.0F
//        val Uy = 0.0F
//
//        val yDegree = calculateDegree(Tx, Ty, Yx, Yy)
        val centerX = 3.0
        val centerY = 3.0
        val x = 5.0
        val y = 5.0

        // 计算相对于圆心的点的偏移
        val relativeX = x - centerX
        val relativeY = y - centerY

        // 计算与圆心的角度（弧度）
        val angleInRadians = atan2(relativeY, relativeX)

        // 将弧度转换为角度
        val angleInDegrees = Math.toDegrees(angleInRadians)

        println("给定点 (${x},${y}) 相对于圆心的角度为：$angleInDegrees 度")
    }

    /**
     * 计算一个点相对于圆心的角度
     */
    fun calculateDegree(x:Float,y:Float,centerX: Float,centerY: Float):Float{
        val xc = x - centerX
        val yc = y - centerY
        return calculateDegree(yc,xc)
    }

    /**
     * 计算一个点到原点的角度
     */
    fun calculateDegree(x:Float,y:Float):Float{
        return Math.toDegrees(atan2(y,x).toDouble()).toFloat()
    }

    @Test
    fun t1(){
        CircleUtil().apply {
//            Fireg degree1=-260.52246 degree2=100.0
            errorDegreeRange = 180/17F/2
            areDegreesClose(-260.52246F, 100.0F)
        }
    }
}